home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / c / MemPools.lha / init.c < prev    next >
C/C++ Source or Header  |  1998-03-12  |  4KB  |  160 lines

  1. /**
  2. ***  MemPools:  malloc() replacement using standard Amiga pool functions.
  3. ***  Copyright  (C)  1994    Jochen Wiedmann
  4. ***    changes       1998    Matthias Andree
  5. ***
  6. ***  This program is free software; you can redistribute it and/or modify
  7. ***  it under the terms of the GNU General Public License as published by
  8. ***  the Free Software Foundation; either version 2 of the License, or
  9. ***  (at your option) any later version.
  10. ***
  11. ***  This program is distributed in the hope that it will be useful,
  12. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ***  GNU General Public License for more details.
  15. ***
  16. ***  You should have received a copy of the GNU General Public License
  17. ***  along with this program; if not, write to the Free Software
  18. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. ***
  20. ***
  21. ***  This file contains the initialization stuff.
  22. ***
  23. ***
  24. ***  Computer:  Amiga 4000
  25. ***
  26. ***  Compilers: gcc 2.7.2
  27. ***             SAS/C 6.58
  28. ***
  29. ***
  30. ***  Author:    Jochen Wiedmann
  31. ***             Am Eisteich 9
  32. ***       72555 Metzingen
  33. ***             Germany
  34. ***
  35. ***             Phone: (0049) 7123 14881
  36. ***             Internet: jochen.wiedmann@uni-tuebingen.de
  37. ***
  38. ***  Bugfixes
  39. ***  Updates:   Matthias Andree
  40. ***             Stormstr. 14
  41. ***             58099 Hagen
  42. ***             Germany
  43. ***
  44. ***             Phone: +49-(0)23 31-96 30 72
  45. ***
  46. ***             E-Mail: mandree@dosis.uni-dortmund.de
  47. ***
  48. **/
  49.  
  50.  
  51. /***************************************************************************
  52. ***
  53. ***  This file uses the auto initialization possibilities of gcc and
  54. ***  SAS/C, respectively.
  55. ***
  56. ***  SAS does this by using names beginning with _STI or _STD, respectively.
  57. ***  gcc uses the asm() instruction, to emulate C++ constructors and
  58. ***  destructors.
  59. ***
  60. ***************************************************************************/
  61.  
  62.  
  63. /*
  64.     Include files and compiler specific stuff
  65. */
  66. #include <stdlib.h>
  67. #include <exec/types.h>
  68. #if defined(__SASC)
  69. #include "my_alib_protos.h"
  70. #else
  71. #include <clib/alib_protos.h>
  72. #endif
  73.  
  74. #include "mempools.h"
  75.  
  76.  
  77.  
  78. #if !defined(__SASC)  &&  !defined(__GNUC__)
  79. #error "Don't know how to handle your compiler."
  80. #endif
  81.  
  82.  
  83. #ifdef DEBUG
  84. const char meatBeaf[40] = {
  85.     'M', 'E', 'A', 'T', 'B', 'E', 'A', 'F',
  86.     'M', 'E', 'A', 'T', 'B', 'E', 'A', 'F',
  87.     'M', 'E', 'A', 'T', 'B', 'E', 'A', 'F',
  88.     'M', 'E', 'A', 'T', 'B', 'E', 'A', 'F',
  89.     'M', 'E', 'A', 'T', 'B', 'E', 'A', 'F',
  90. };
  91. struct MinList memList;
  92. #endif
  93.  
  94. APTR __MemPool;
  95.  
  96.  
  97.  
  98. #ifndef DEBUG
  99. /* STATIC */
  100. #endif
  101. #if defined(__SASC)
  102. __stdargs
  103. #endif
  104. LONG _STI_InitMemFunctions(VOID)
  105.  
  106. {
  107. #ifdef DEBUG
  108.     NewList((struct List *) &memList);
  109. #endif
  110.     if (!(__MemPool = LibCreatePool(__MemPoolFlags,
  111.                     __MemPoolPuddleSize,
  112.                     __MemPoolThreshSize))) {
  113. #if defined(__SASC)
  114.     return(TRUE);
  115. #elif defined(__GNUC__)
  116.     abort();
  117. #endif
  118.     }
  119.  
  120.     return(FALSE);
  121. }
  122.  
  123.  
  124. #ifndef DEBUG
  125. /* STATIC */
  126. #endif
  127. #if defined(__SASC)
  128. __stdargs
  129. #endif
  130. VOID _STD_TerminateMemFunctions(VOID)
  131.  
  132. {
  133. #ifdef DEBUG
  134.     /*  Be safe, that all memory blocks are checked by calling  */
  135.     /*  free() on them.                                         */
  136.     static int called = FALSE;  /*  Be reentrant.   */
  137.  
  138.     if (!called) {
  139.     memBlock *block;
  140.  
  141.     called = TRUE;
  142.     block = (memBlock *) memList.mlh_Head;
  143.     while (block->node.mln_Succ) {
  144.         free(block+1);
  145.     }
  146.     }
  147. #endif
  148.  
  149.     if (__MemPool)
  150.     { LibDeletePool(__MemPool);
  151.       __MemPool = NULL;
  152.     }
  153. }
  154.  
  155.  
  156. #if defined(__GNUC__)
  157. __asm ("  .text;  .stabs \"___CTOR_LIST__\",22,0,0,__STIInitMemFunctions");
  158. __asm ("  .text;  .stabs \"___DTOR_LIST__\",22,0,0,__STDTerminateMemFunctions");
  159. #endif
  160.